/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kallsonys.session;

import com.kallsonys.object.Creditcard;
import com.kallsonys.object.Customer;
import com.kallsonys.object.ws.ListElement;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author alladiab
 */
@Stateless
public class CreditcardFacade extends AbstractFacade<Creditcard> {
    @PersistenceContext(unitName = "Kallsonys-WarPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public CreditcardFacade() {
        super(Creditcard.class);
    }
    
    
    public List<Creditcard> getByCustomerId(long customerId) {
        List<Creditcard> p = null;

        Query queryByCustomerId = em.createNamedQuery("Creditcard.findByCustumerId");
        queryByCustomerId.setParameter("customerid", new Customer(customerId));
        p = (List<Creditcard>) queryByCustomerId.getResultList();

        return p;
    }
    
    
    public long CreateCreditCard( com.kallsonys.object.Creditcard creditcard )
    {
        this.create(creditcard);
        
        return creditcard.getCreditcardid();
    }
    
    public List<ListElement> getCreditCards()
    {
        List<ListElement> lstItems = new ArrayList<ListElement>();
        
        lstItems.add(new ListElement("1", "AMEX"));
        lstItems.add(new ListElement("2", "Visa"));
        lstItems.add(new ListElement("3", "Master"));
        
        return lstItems;
    }
    
}
